package com.service.impl;

import com.entity.Leave;
import com.mapper.LeaveMapper;
import com.service.LeaveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.sys.DepartmentService;
import com.service.sys.UserVoService;
import com.vo.LeaveVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author clay
 * @since 2022-03-27
 */
@Service
public class LeaveServiceImpl extends ServiceImpl<LeaveMapper, Leave> implements LeaveService {

    @Resource
    private LeaveMapper leaveMapper;

    @Resource
    private UserVoService userVoService;

    @Resource
    private DepartmentService departmentService;

    //动态查询
    @Override
    public List<LeaveVo> select(Leave leave) {
        List<Leave> leaveList = leaveMapper.queryLeave(leave);
        List<LeaveVo> leaveVoList = new ArrayList<>();
        for (Leave leave1 : leaveList) {
            LeaveVo leaveVo = new LeaveVo();
            BeanUtils.copyProperties(leave1, leaveVo);
            //申请人信息
            leaveVo.setProposer(userVoService.getById(leave1.getUserId()));
            //审核人信息
            leaveVo.setReviewer(userVoService.getById(leave1.getLeaderId()));
            leaveVo.setDepartmentVo(departmentService.getById(leave1.getDepartmentId()));
            leaveVoList.add(leaveVo);
        }
        return leaveVoList;
    }
}
